home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Utils / IceBreaker / Source / Console / IceBreaker.c next >
Encoding:
C/C++ Source or Header  |  1997-07-08  |  3.8 KB  |  135 lines

  1. /*
  2. ** ICE BREAKER (CONSOLE VERSION) V1.0
  3. ** ----------------------------------
  4. ** Author:    Paul Manias
  5. ** Copyright: DreamWorld Productions 1997.
  6. ** Compile:   sc IceBreaker.c nolink
  7. **            PhxAss /IceAssembler.asm
  8. **            slink FROM lib:c.o,IceBreaker.o,/IceAssembler.o TO IceBreakerCon LIBRARY LIB:sc.lib,LIB:Amiga.lib
  9. **
  10. ** Doc:       This is the entry code for IceBreaker, it sets things up
  11. **            so that the assembler code is ready to intercept debug
  12. **            messages.  This particular version outputs to a console
  13. **            window - preferably KCON: but CON: is accepted as well.
  14. **
  15. */
  16.  
  17. #include <proto/games.h>
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <dos/dos.h>
  21.  
  22. extern struct ExecBase *SysBase;
  23. extern struct GFXBase *GFXBase;
  24.  
  25. #define LVODEBUGMESSAGE -378
  26. #define LVOERRORMESSAGE -384
  27. #define LVOSTEPBACK     -390
  28.  
  29. extern ULONG (libDebugMessage)();
  30. extern ULONG (libErrorMessage)();
  31. extern ULONG (libStepBack)();
  32.  
  33. struct GMSBase *GMSBase;
  34. struct Task *maintask;
  35. struct Task *edittask = NULL;
  36.  
  37. BPTR conhandle=0;      /* Handle to output debug information */
  38.  
  39. /***************************** INITIALISATION CODE *********************************/
  40.  
  41. void mainroutine(void);
  42. long getlen(char string[]);
  43. void wtext(char string[]);
  44. BPTR openconsole(void);
  45.  
  46. void main(void)
  47. {
  48.  void *oldDebugMessage;
  49.  void *oldErrorMessage;
  50.  void *oldStepBack;
  51.  
  52.  maintask = FindTask(0);
  53.  
  54.  if (GMSBase = (struct GMSBase *) OpenLibrary("GMS:libs/dpkernal.library",0)) {
  55.   if (DebugActive() == ERR_OK) {
  56.    if (GFXBase = (struct GFXBase *) OpenLibrary("graphics.library",0)) {
  57.     if (conhandle = openconsole()) {
  58.  
  59.        Forbid();
  60.        oldDebugMessage = SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,&libDebugMessage);
  61.        oldErrorMessage = SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,&libErrorMessage);
  62.        oldStepBack     = SetFunction((struct Library *)GMSBase,LVOSTEPBACK,&libStepBack);
  63.        SumLibrary((struct Library *)GMSBase);
  64.        Permit();
  65.  
  66.        mainroutine();
  67.  
  68.        Forbid();
  69.        SetFunction((struct Library *)GMSBase,LVODEBUGMESSAGE,oldDebugMessage);
  70.        SetFunction((struct Library *)GMSBase,LVOERRORMESSAGE,oldErrorMessage);
  71.        SetFunction((struct Library *)GMSBase,LVOSTEPBACK,oldStepBack);
  72.        SumLibrary((struct Library *)GMSBase);
  73.        Permit();
  74.  
  75.     Close(conhandle);
  76.     }
  77.    CloseLibrary((struct Library *)GFXBase);
  78.    }
  79.   DebugInactive();
  80.   }
  81.  CloseLibrary((struct Library *)GMSBase);
  82.  }
  83. }
  84.  
  85. /*********************************** MAIN LOOP *************************************/
  86.  
  87. void mainroutine(void)
  88. {
  89.   LONG result;
  90.  
  91.   wtext("Welcome to IceBreaker V1.0, the debugger for GMS programs.\n");
  92.   wtext("This program will wait until a program using GMS is executed.  Any\n");
  93.   wtext("debug messages that are sent while it is active will be intercepted\n");
  94.   wtext("and printed out to this window.\n\n");
  95.   wtext("Press CTRL-C at any time to exit.\n\n");
  96.   wtext("Type                 | Data\n");
  97.   wtext("---------------------+---------------------------------------------\n");
  98.  
  99.   do {
  100.      result = Wait(SIGBREAKF_CTRL_C);
  101.   } while (!(result & SIGBREAKF_CTRL_C));
  102.  
  103. }
  104.  
  105. /***********************************************************************************/
  106.  
  107. void wtext(char string[]) {
  108.   Write(conhandle,(ULONG)string,getlen(string));
  109. }
  110.  
  111. /***********************************************************************************/
  112.  
  113. long getlen(char string[]) {
  114.   int length=0;
  115.  
  116.   while (string[length] != 0) {
  117.     length++;
  118.     if (length > 256) break;
  119.   }
  120.   return(length);
  121. }
  122.  
  123. /***********************************************************************************/
  124.  
  125. BPTR openconsole(void) {
  126.   BPTR handle;
  127.  
  128.   if (handle = Open("KCON:0/20/640/200/Function Output/SCREEN IceBreaker",MODE_OLDFILE)) {
  129.      return(handle);
  130.   }
  131.   else
  132.      return(Open("CON:0/20/640/200/Function Output/SCREEN IceBreaker",MODE_OLDFILE));
  133. }
  134.  
  135.